package jman.teemwork11;

import java.sql.SQLException;

public class SchoolManager {
	public boolean addStudent(Student s){
		DatebaseManager dm=new DatebaseManager();
		dm.getCon();
		dm.read("select * from student");
		try {
			while(dm.getRs().next()){
				if(dm.getRs().getString("id").equals(Integer.toString(s.getId()))){
					System.out.println("该学生已存在");
				}else{
					dm.add("insert into student (id,studentname,sex,age,weight) values ("+s.getId()+",'"+s.getStudentName()+"','"+s.getSex()+"',"+s.getAge()+","+s.getWeight()+")");
				}
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
		}
		dm.closePs();
		dm.closeCon();
		return true;
	}
	public void selectLowScore(){
		DatebaseManager dm=new DatebaseManager();
		dm.getCon();
		dm.read("select s.id,s.studentname,h.score from student as s right join homework as h on s.id=h.id order by score limit 3");
		try {
			while(dm.getRs().next()){
				System.out.println("学号："+dm.getRs().getString("id")+'\t'+"姓名："+dm.getRs().getString("studentname")+'\t'+"成绩："+dm.getRs().getString("score"));
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		dm.closeRs();
		dm.closePs();
		dm.closeCon();
	}
}
